﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Histograms
{
    /// <summary>
    /// 
    /// </summary>
    public class StatisticValue
    {
        public Color m_Color = Color.Transparent;
        internal int m_nGrayValue = -1;
        private Point m_ptPixel = Point.Empty;
        internal int m_R = -1;
        internal int m_G = -1;
        internal int m_B = -1;
        internal int m_A = -1;
        internal float m_fLuminance = -1.0f;
        internal float m_fHue = -1.0f;
        internal float m_fSaturation = -1.0f;
        internal float m_fBrightness = -1.0f;
        internal int m_nSumRGB = -1;
        internal int m_nSumARGB = -1;
        internal int m_nMulRGB = -1;
        internal int m_nMulARGB = -1;

        /// <summary>
        /// Initializes a new instance of the <see cref="StatisticValue"/> class.
        /// </summary>
        /// <param name="_color">The _color.</param>
        /// <param name="_ptPixel">The _PT pixel.</param>
        /// <param name="_bNocalculate">if set to <c>true</c> [_b nocalculate].</param>
        internal StatisticValue(Color _color, Point _ptPixel, bool _bNocalculate)
        {
            this.m_Color = _color;
            if (!_bNocalculate)
            {
                CalculateValues(_color, _ptPixel);
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="StatisticValue"/> class.
        /// </summary>
        /// <param name="_color">The _color.</param>
        public StatisticValue(Color _color)
            : this(_color, Point.Empty)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="StatisticValue"/> class.
        /// </summary>
        /// <param name="_color">The _color.</param>
        /// <param name="_ptPixel">The _PT pixel.</param>
        public StatisticValue(Color _color, Point _ptPixel)
        {
            CalculateValues(_color, _ptPixel);
        }

        /// <summary>
        /// Calculates the values.
        /// </summary>
        /// <param name="_color">The _color.</param>
        /// <param name="_ptPixel">The _PT pixel.</param>
        private void CalculateValues(Color _color, Point _ptPixel)
        {
            m_Color = _color;
            m_ptPixel = _ptPixel;
            m_R = m_Color.R;
            m_G = m_Color.B;
            m_B = m_Color.B;
            m_A = m_Color.A;

            m_fLuminance = ColorFunctions.GetLuminance(m_Color);
            m_fHue = m_Color.GetHue();
            m_fSaturation = m_Color.GetSaturation();
            m_fBrightness = m_Color.GetBrightness();
            m_nSumRGB = m_Color.R + m_Color.G + m_Color.B;
            m_nSumARGB = m_Color.A + m_Color.R + m_Color.G + m_Color.B;
            m_nMulRGB = m_Color.R * m_Color.G * m_Color.B;
            m_nMulARGB = m_Color.A * m_Color.R * m_Color.G * m_Color.B;
        }

        /// <summary>
        /// Gets the R.
        /// </summary>
        /// <value>The R.</value>
        public int R
        {
            get { return m_R; }
        }

        /// <summary>
        /// Gets the G.
        /// </summary>
        /// <value>The G.</value>
        public int G
        {
            get { return m_G; }
        }

        /// <summary>
        /// Gets the B.
        /// </summary>
        /// <value>The B.</value>
        public int B
        {
            get { return m_B; }
        }

        /// <summary>
        /// Gets the A.
        /// </summary>
        /// <value>The A.</value>
        public int A
        {
            get { return m_A; }
        }

        /// <summary>
        /// Gets the color.
        /// </summary>
        /// <value>The color.</value>
        public Color Color
        {
            get { return m_Color; }
        }

        /// <summary>
        /// Gets the point.
        /// </summary>
        /// <value>The point.</value>
        public Point Point
        {
            get { return m_ptPixel; }
        }

        /// <summary>
        /// Gets the X.
        /// </summary>
        /// <value>The X.</value>
        public int X
        {
            get { return m_ptPixel.X; }
        }

        /// <summary>
        /// Gets the Y.
        /// </summary>
        /// <value>The Y.</value>
        public int Y
        {
            get { return m_ptPixel.Y; }
        }

        /// <summary>
        /// Gets the luminance.
        /// </summary>
        /// <value>The luminance.</value>
        public float Luminance
        {
            get { return m_fLuminance; }
        }

        /// <summary>
        /// Gets the hue.
        /// </summary>
        /// <value>The hue.</value>
        public float Hue
        {
            get { return m_fHue; }
        }

        /// <summary>
        /// Gets the saturation.
        /// </summary>
        /// <value>The saturation.</value>
        public float Saturation
        {
            get { return m_fSaturation; }
        }

        /// <summary>
        /// Gets the brightness.
        /// </summary>
        /// <value>The brightness.</value>
        public float Brightness
        {
            get { return m_fBrightness; }
        }

        /// <summary>
        /// Gets the color value.
        /// </summary>
        /// <value>The color value.</value>
        public int ColorValue
        {
            get { return m_Color.ToArgb(); }
        }

        /// <summary>
        /// Gets the gray value.
        /// </summary>
        /// <value>The gray value.</value>
        public int GrayValue
        {
            get { return m_nGrayValue; }
        }

        /// <summary>
        /// Gets the sum RGB.
        /// </summary>
        /// <value>The sum RGB.</value>
        public int SumRGB
        {
            get { return m_nSumRGB; }
        }

        /// <summary>
        /// Gets the sum ARGB.
        /// </summary>
        /// <value>The sum ARGB.</value>
        public int SumARGB
        {
            get { return m_nSumARGB; }
        }

        /// <summary>
        /// Gets the mul RGB.
        /// </summary>
        /// <value>The mul RGB.</value>
        public int MulRGB
        {
            get { return m_Color.R * m_Color.G * m_Color.B; }
        }

        /// <summary>
        /// Gets the mul ARGB.
        /// </summary>
        /// <value>The mul ARGB.</value>
        public int MulARGB
        {
            get { return m_Color.A * m_Color.R * m_Color.G * m_Color.B; }
        }
    }
}
